class TreeNode {
    constructor(val) {
        this.val = val;
        this.left = null;
        this.right = null;
    }
}

class BinaryTree {
    constructor() {
        this.root = null;
    }

    

    preOrder(root) {
        if (!root) {
            return [];
        }
        const res = [];
        const dfs = (node, res) => {
            res.push(node.val);
            if (node.left) {
                dfs(node.left, res);
            }
            if (node.right) {
                dfs(node.right, res);
            }
        };
        dfs(this.root, res);
        return res;
    }

    inOrder(root) {
        if (!root) {
            return [];
        }
        const res = [];
        const dfs = (node, res) => {
            if (node.left) {
                dfs(node.left, res);
            }
            res.push(node.val);
            if (node.right) {
                dfs(node.right, res);
            }
        };
        dfs(this.root, res);
        return res;
    }

    postOrder(root) {
        if (!root) {
            return [];
        }
        const res = [];
        const dfs = (node, res) => {
            if (node.left) {
                dfs(node.left, res);
            }
            if (node.right) {
                dfs(node.right, res);
            }
            res.push(node.val);
        };
        dfs(this.root, res);
        return res;
    }

}


// 前序遍历
